#include "event.h"
#include "async_event_args.h"

namespace nsshare
{
namespace sys
{

AsyncEventArgs::AsyncEventArgs()
    : user_token_(0)
{
    overlapped_.Internal = 0;
    overlapped_.InternalHigh = 0;
    overlapped_.Offset = 0;
    overlapped_.OffsetHigh = 0;
    overlapped_.hEvent = 0;
}

AsyncEventArgs::AsyncEventArgs(const Event & e)
    : user_token_(0)
{
    overlapped_.Internal = 0;
    overlapped_.InternalHigh = 0;
    overlapped_.Offset = 0;
    overlapped_.OffsetHigh = 0;
    overlapped_.hEvent = e.WaitableHandle();
}

void * AsyncEventArgs::user_token() const
{
    return user_token_;
}

void AsyncEventArgs::set_user_token(void * token)
{
    user_token_ = token;
}

void AsyncEventArgs::SuppressIOCP()
{
    DWORD value = reinterpret_cast<DWORD>(overlapped_.hEvent);
    if(value)
    {
        value |= 0x1;
        overlapped_.hEvent = reinterpret_cast<HANDLE>(value);
    }
}

}
}
